<%--
  Created by IntelliJ IDEA.
  User: LT
  Date: 2018-10-25
  Time: 15:46
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <link href="${pageContext.request.contextPath}/statics/hplus/css/bootstrap.min.css" rel="stylesheet">
    <link href="${pageContext.request.contextPath}/statics/hplus/css/plugins/bootstrap-table/bootstrap-table.min.css" rel="stylesheet">
    <script src="${pageContext.request.contextPath}/statics/hplus/js/jquery.min.js"></script>
    <script src="${pageContext.request.contextPath}/statics/hplus/js/bootstrap.min.js"></script>
    <script src="${pageContext.request.contextPath}/statics/hplus/js/plugins/bootstrap-table/bootstrap-table.min.js"></script>
    <script src="${pageContext.request.contextPath}/statics/hplus/js/plugins/bootstrap-table/locale/bootstrap-table-zh-CN.min.js"></script>
    <script>
        function searcha() {
            //返回表格的 Options。
            var opts = $("#taocanpeizhis").bootstrapTable("getOptions") ;
            var limit = opts.pageSize ;
            var offset = (opts.pageNumber-1) * limit;
            var username = $("#username").val() ;
            $.post("${pageContext.request.contextPath}/taocanpeizhi/queryByName",{'name':username,'limit':limit,'offset':offset},function (data) {
                // var mydata = eval("("+data+")") ;
                //重新绑定表格数据
                $("#taocanpeizhis").bootstrapTable('load',data) ;
            })
        }

        $(function () {
            $("#taocanchanpin").bootstrapTable({
                url:'${pageContext.request.contextPath}/taocanpeizhi/queryId1',
                columns:[
                    {
                        field:'taocan_Name',
                        title:'名称',
                        align:'center'
                    },
                    {
                        field:'jifen_Jiage',
                        title:'原价',
                        align:'center'
                    },
                    {
                        field:'huiyuanleixing_Name',
                        title:'会员',
                        align:'center'
                    },
                    {
                        field:'dianpu_Name',
                        title:'店铺',
                        align:'center'
                    },
                    {
                        field:'jifen_Jiage',
                        title:'当前价格'
                    },
                    {
                        field:'kaishi_Shijian',
                        title:'开始时间',
                        align:'center'
                    },
                    {
                        field:'jieshu_Shijian',
                        title:'结束时间',
                        align:'center'
                    }
                ],
            }) ;
        }) ;



        $(function () {
            $("#taocanpeizhis").bootstrapTable({
                url:'${pageContext.request.contextPath}/taocanpeizhi/queryByName',
                //设置每页多少条数据
                pageSize:4,
                pageList:[4,8,16],
                height:380,
                pageNumber:1,
                //启用分页，但是默认情况下，是客户端分页的
                pagination:true,
                //启用服务器端分页
                sidePagination:'server',
                queryParams:function(params){
                    var temp = {  //这里的键的名字和控制器的变量名必须一直，这边改动，控制器也需要改成一样的
                        limit: params.limit,  //页面大小
                        offset: params.offset, //页码
                        username:$("#username").val()
                    };
                    return temp;
                },
                columns:[
                    {
                        field:'xiangmuleixing_Name',
                        title:'套餐类型',
                        align:'center'
                    },
                    {
                        field:'taocan_Id',
                        title:'编号',
                        align:'center'
                    },
                    {
                        field:'taocan_Name',
                        title:'名称',
                        align:'center'
                    },
                    {
                        field:'fuwuxiangmu_Name',
                        title:'分类',
                        align:'center'
                    },
                    {
                        field:'chanpindanwei_name',
                        title:'单位',
                        align:'center'
                    },
                    {
                        field:'taocan_Jiage',
                        title:'售价',
                        align:'center'
                    },
                    {
                        field:'zhuangtai',
                        title:'状态',
                        align:'center'
                    },
                    {
                        title:'促销明细',
                        align:'center',
                        formatter:function(value,row,index){
                            var d=""+row.shangpin_Id;
                            return "<button style='height: 35px' class='btn  btn-primary' onclick='query("+d+")'>" +
                                "<span class=\"glyphicon glyphicon-search\" aria-hidden=\"true\" title='促销明细'\"><p style='float:right;margin-top: -2px'>促销明细</p></span></button>"
                        }
                    }
                ],
            }) ;
        }) ;

        function query(shangpin_Id){
            $("#showtaocanxq").modal("show") ;
            $.post("${pageContext.request.contextPath}/taocanpeizhi/queryId1",{shangpin_Id:shangpin_Id},function (data) {
                // var mydata = eval("("+data+")") ;
                //重新绑定表格数据
                $("#taocanchanpin").bootstrapTable('load',data) ;
            })
        }


    </script>

</head>
<body>

<div class="panel panel-default">
    <div class="panel-heading">
        <h3 class="panel-title">特价配置</h3>
    </div>
    <div class="panel-body">
        <div class="row">
            <div class="col-sm-6">
                <%--<button onclick="toadd()" class="btn btn-primary"><span class="glyphicon glyphicon-plus"></span>&nbsp;&nbsp;增加</button>--%>
            </div>
            <div class="col-sm-6">
                <form  class="form-inline pull-right">
                    <input id="username" type="text" class="form-control">
                    <button class="btn btn-primary" onclick="searcha()" type="button"><span class="glyphicon glyphicon-search"></span>&nbsp;&nbsp;搜索</button>
                </form>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-12">
                <table id="taocanpeizhis"></table>
            </div>
        </div>

    </div>
</div>


<!--套餐详情模态框-->
<div class="modal inmodal" id="showtaocanxq">
    <div class="modal-dialog" style="height: 300px;width: 800px">
        <div class="modal-content animated bounceInRight">
            <table id="taocanchanpin"></table>
            <div class="modal-footer">
                <button type="button" class="btn btn-white" data-dismiss="modal">关闭</button>
            </div>
        </div>
    </div>
</div>
</body>
</html>
